package com.worley.argutils.bk;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

public class RunState {

    public static final int BATCH_UPDATE_COUNT = 1000;

    private AtomicInteger totalReq = new AtomicInteger();

    private LongAdder totalTime = new LongAdder();

    // 总请求数
    private int count;

    private String value;

    public RunState(int count, String value) {
        super();
        this.count = count;
        this.value = value;
    }

    public int getTotalReq() {
        return totalReq.get();
    }

    public int accTotalReq() {
        return totalReq.addAndGet(BATCH_UPDATE_COUNT);
    }

    public long getTotalNanoTime() {
        return totalTime.longValue();
    }

    public void accTotalNanoTime(long c) {
        totalTime.add(c);
    }
    
    public int getCount() {
        return count;
    }

    public String getValue() {
        return value;
    }

    public int getLoops() {
        int loops = count / BATCH_UPDATE_COUNT;
        return loops <= 0 ? 1 : loops;
    }

}
